import { useI18n } from '/@/hooks/web/useI18n';
import { BasicColumn, BasicTableProps, FormProps } from '/@/components/Table';
import { loginUserCusList } from '/@/api/bas/cus/basCus';

const { t } = useI18n('sys.empUser');

const modalProps = {
  title: t('客户选择'),
};

const searchForm: FormProps = {
  baseColProps: { lg: 6, md: 8 },
  labelWidth: 80,
  schemas: [
    {
      label: t('客户编码'),
      field: 'cusCode',
      component: 'Input',
    },
    {
      label: t('客户名称'),
      field: 'basCus.name',
      component: 'Input',
    },
  ],
};

const tableColumns: BasicColumn[] = [
  {
    title: t('客户编码'),
    dataIndex: 'basCus.code',
    key: 'cus.code',
    sorter: true,
    width: 100,
    align: 'left',
    slot: 'firstColumn',
  },
  {
    title: t('客户名称'),
    dataIndex: 'basCus.name',
    key: 'a.name',
    sorter: true,
    width: 100,
    align: 'left',
  },
  {
    title: t('客户简称'),
    dataIndex: 'basCus.abbName',
    key: 'a.abb_name',
    sorter: true,
    width: 100,
    align: 'left',
  },
];

const tableProps: BasicTableProps = {
  api: loginUserCusList,
  beforeFetch: (params) => {
    params['isAll'] = true;
    return params;
  },
  afterFetch: (data) => {
    const dataList = data.map((item) => {
      item.cusName = item.basCus.name;
      return item;
    });
    return dataList;
  },
  columns: tableColumns,
  formConfig: searchForm,
  rowKey: 'cusCode',
};

export default {
  modalProps,
  tableProps,
  itemCode: 'cusCode',
  itemName: 'cusName',
};
